﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{
    public class PG2:Group
    {

        // Fields
        //有关化学转化、干湿沉降、扩散、烟羽抬升、复杂地形等的变量的选择，有些变量具有经验值和默认值，有些变量需要通过计算公式计算。




        /// <summary>
        /// 近场垂向分布的计算方法
        /// =1，均一方法
        /// 高斯分布方法
        /// </summary>
        private int m_MGAUSS = 1;

        public int MGAUSS
        {
            get { return m_MGAUSS; }
            set { m_MGAUSS = value; }
        }

        //地形调整方法  0=无调整 1=ISC调整 2=简单 3=部分烟雨轨迹调整
        /// <summary>
        /// 地形调整方法
        /// 0=无调整 
        /// 1=ISC调整 
        /// 2=简单CALPUFF地形调整 
        /// 3=部分烟羽轨迹调整
        /// </summary>
        private int m_MCTADJ = 2;

        public int MCTADJ
        {
            get { return m_MCTADJ; }
            set { m_MCTADJ = value; }
        }

        /// <summary>
        /// 是否考虑次网格尺度复杂地形ctsg
        /// =0,不考虑
        /// =1，考虑CTSG 
        /// </summary>
        private int m_MCTSG = 0;

        public int MCTSG
        {
            get { return m_MCTSG; }
            set { m_MCTSG = value; }
        }


        /// <summary>
        /// 近场烟片按照拉长的“烟片”来模拟
        /// 0=否 
        /// 1=是
        /// </summary>
        private int m_MSLUG = 0;

        public int MSLUG
        {
            get { return m_MSLUG; }
            set { m_MSLUG = value; }
        }
        /// <summary>
        /// 是否模拟过渡烟羽上升
        /// 0=只计算最后上升 
        /// 1=计算过渡上升
        /// 注:过渡烟羽上升的计算只针对具有下洗效应的源
        /// </summary>
        private int m_MTRANS = 1;

        public int MTRANS
        {
            get { return m_MTRANS; }
            set { m_MTRANS = value; }
        }

        //是否模拟烟囱顶下洗 0=否 1=是
        private int m_MTIP = 1;

        public int MTIP
        {
            get { return m_MTIP; }
            set { m_MTIP = value; }
        }

        /// <summary>
        /// 计算点源建筑物下洗的言语抬升的方法
        /// =0，布朗吉斯抬升公式
        /// =1，数值烟羽抬升
        /// </summary>
        private int m_MRISE = 1;

        public int MRISE
        {
            get { return m_MRISE; }
            set { m_MRISE = value; }
        }



        /// <summary>
        ///  建筑物下洗方案  1=isc方法 2=prime方法
        /// </summary>
        private int m_MBDW = 1;

        public int MBDW
        {
            get { return m_MBDW; }
            set { m_MBDW = value; }
        }


        /// <summary>
        ///是否考虑烟囱顶上的垂直风剪切
        /// </summary>
        private int m_MSHEAR = 0;

        public int MSHEAR
        {
            get { return m_MSHEAR; }
            set { m_MSHEAR = value; }
        }


        /// <summary>
        /// 是否允许烟团分裂 0=否 1=是
        /// </summary>
        private int m_MSPLIT = 0;

        public int MSPLIT
        {
            get { return m_MSPLIT; }
            set { m_MSPLIT = value; }
        }


        /// <summary>
        /// 化学转化机制
        /// 0=不模拟 
        /// 1=内部计算 MESOPUFF II方案
        /// 2=使用自定义速率文件 
        /// 3=rivad/arm3方案
        /// 4=二次有机气溶胶公式计算(MESOPUFF II 方案 for OH)
        /// </summary>
        private int m_MCHEM = 0;

        public int MCHEM
        {
            get { return m_MCHEM; }
            set { m_MCHEM = value; }
        }

        /// <summary>
        /// 水相转化标识
        /// =0，不考虑水相转化
        /// 为水相转化调整转变速率
        /// Used only if MCHEM = 1, or 3
        /// </summary>
        private int m_MAQCHEM = 0;

        public int MAQCHEM
        {
            get { return m_MAQCHEM; }
            set { m_MAQCHEM = value; }
        }


        /// <summary>
        /// 是否模拟湿移除0=否 ，1=是 
        /// </summary>
        private int m_MWET = 1;

        public int MWET
        {
            get { return m_MWET; }
            set { m_MWET = value; }
        }

        /// <summary>
        /// 是否模拟干沉降0=否，1=是
        /// </summary>
        private int m_MDRY = 1;

        public int MDRY
        {
            get { return m_MDRY; }
            set { m_MDRY = value; }
        }


        /// <summary>
        /// z重力沉降（考虑烟羽倾斜。
        /// =0，不考虑
        /// =1，考虑       
        /// </summary>
        private int m_MTILT = 0;

        public int MTILT
        {
            get { return m_MTILT; }
            set { m_MTILT = value; }
        }

        //用于计算水平和垂直扩散系数的方法
        //1=σv and σw从PROFILE.DAT的 获得
        //2=σv and σw从微气象学变量的内部计算得到
        //3=在RUAL区域使用PG扩散系数，以及在URBAN区域使用的MP系数
        //4=与3同，除了PG系数从 mesopuff公式计算外
        //5=CTDM用于稳定和不稳定下的不确定条件。σv and σw从PROFILE.DAT的 获得
        private int m_MDISP = 2;

        public int MDISP
        {
            get { return m_MDISP; }
            set { m_MDISP = value; }
        }
        private int m_MTURBVW = 3;

        /// <summary>
        ///    是否使用 Sigma-v/sigma-thetaw，σw测量法，Used only if MDISP = 1 or 5
        /// =1，使用从PROFILE.DAT读取的 sigma-v or sigma-theta 计算 sigma-y
        /// =2.，使用从PROFILE.DAT读取的sigma-w计算 sigma-z
        /// =3，使用从PROFILE.DAT读取的sigma-(v/theta) and sigma-w计算sigma-y and sigma-z
        /// =4,使用从PLMMET.DAT读取的sigma-theta ，计算sigma-y       
        /// </summary>
        public int MTURBVW
        {
            get { return m_MTURBVW; }
            set { m_MTURBVW = value; }
        }





        /// <summary>
        /// 缺少湍流数据值时计算扩散参数的备用方法，Used only if MDISP = 1 or 5
        /// =2，从微气象参数中计算σv and σw
        /// =3，在Rural区域使用PG扩散系数，在Urban区域使用MP系数
        /// =4，与3相同，出了PG系数采用MESOPUFF II计算
        /// </summary>
        private int m_MDISP2 = 3;

        public int MDISP2
        {
            get { return m_MDISP2; }
            set { m_MDISP2 = value; }
        }
        /// <summary>
        /// 诊断特性,计算拉格朗日时间尺度Sigma-y的方法
        ///   0 = Draxler default 617.284 (s)
        ///   1 = Computed as Lag. Length / (.75 q) -- after SCIPUFF    10 < Direct user input (s)             -- e.g., 306.9
        /// </summary>
        private int m_MTAULY = 0;

        public int MTAULY
        {
            get { return m_MTAULY; }
            set { m_MTAULY = value; }
        }
        /// <summary>
        /// [诊断特性]计算平流湍流衰减时间尺度的方法   
        ///      0 = 无平流湍流
        ///      1 = Computed (OPTION NOT IMPLEMENTED)       10 < Direct user input (s)   -- e.g., 800
        /// </summary>
        private int m_MTAUADV = 0;

        public int MTAUADV
        {
            get { return m_MTAUADV; }
            set { m_MTAUADV = value; }
        }
        /// <summary>
        /// 计算sigma-v & sigma-w湍流的方法 (Used only if MDISP = 2 or MDISP2 = 2)
        ///       1 = 标准 CALPUFF 程序
        ///       2 = AERMOD程序
        /// </summary>
        private int m_MCTURB = 1;

        public int MCTURB
        {
            get { return m_MCTURB; }
            set { m_MCTURB = value; }
        }


        /// <summary>
        /// PG sigma-y,z 随不同的粗糙度调整(0 = no, 1 = yes)
        /// </summary>
        private int m_MROUGH = 0;

        public int MROUGH
        {
            get { return m_MROUGH; }
            set { m_MROUGH = value; }
        }

        /// <summary>
        /// 对于点源，是否抬高逆温层的部分烟羽穿透(0 = no, 1 = yes)
        /// </summary>
        private int m_MPARTL = 1;

        public int MPARTL
        {
            get { return m_MPARTL; }
            set { m_MPARTL = value; }
        }



        /// <summary>
        /// 对于浮力面源，是否抬高逆温层的部分烟羽穿透(0 = no, 1 = yes)
        /// </summary>
        private int m_MPARTLBA = 1;

        public int MPARTLBA
        {
            get { return m_MPARTLBA; }
            set { m_MPARTLBA = value; }
        }


        /// <summary>
        /// 是否使用PROFILE.DAT扩展记录提供的逆温强度(0 = no, 从温度梯度中计算; 1= yes)
        /// </summary>
        private int m_MTINV = 0;

        public int MTINV
        {
            get { return m_MTINV; }
            set { m_MTINV = value; }
        }


        /// <summary>
        ///  在对流层内是否用概率分布函数方法计算扩散(0 = no, 1 = yes)
        /// </summary>
        private int m_MPDF = 1;

        public int MPDF
        {
            get { return m_MPDF; }
            set { m_MPDF = value; }
        }

        /// <summary>
        /// 是否在海岸边界内应用子网格尺度的热内边界层(0 = no, 1 = yes)
        /// </summary>

        private int m_MSGTIBL = 0;

        public int MSGTIBL
        {
            get { return m_MSGTIBL; }
            set { m_MSGTIBL = value; }
        }

        /// <summary>
        /// 是否考虑边界条件
        /// 1 = yes, 使用格式化文件 BCON.DAT 
        /// 2 = yes, 使用非格式化文件 CONC.DAT 

        /// </summary>
        private int m_MBCON = 0;

        public int MBCON
        {
            get { return m_MBCON; }
            set { m_MBCON = value; }
        }

        /// <summary>
        /// 是否保存单独源的计算结果(0 = no, 1 = yes)
        /// </summary>

        private int m_MSOURCE = 1;

        public int MSOURCE
        {
            get { return m_MSOURCE; }
            set { m_MSOURCE = value; }
        }

        /// <summary>
        /// 是否配置FOG模型(0 = no, 1 = yes)
        /// 1 = yes  结果报告在 PLUME Mode format
        /// 2 = yes   结果报告在 RECEPTOR Mode format

        /// </summary>
        private int m_MFOG = 0;

        public int MFOG
        {
            get { return m_MFOG; }
            set { m_MFOG = value; }
        }



        /// <summary>
        ///     检查选项是否为常规选项
        ///     0 = 不检查
        ///     1 = 技术参数必须符合EPA的规定
        ///     EPA参数
        ///     METFM =1
        ///     AVET= 60. (Min)
        ///     MGAUSS =1
        ///     MCTADJ =3
        ///     MTRANS =1
        ///     MTIP= 1
        ///     MCHEM =1 (if modeling SOx, NOx)
        ///     MWET =1
        ///     MDRY =1
        ///     MDISP =3
        ///     MROUGH= 0
        ///     MPARTL= 1
        ///     SYTDEP =550
        ///     MHFTSZ =0
        /// </summary>
        private int m_MREG = 0;

        public int MREG
        {
            get { return m_MREG; }
            set { m_MREG = value; }
        }


        public override void ReadFromGroup(Dictionary<string, string> dic)
        {
            foreach (KeyValuePair<string, string> m_dic in dic)
            {

                if (m_dic.Key == "MGAUSS")
                {
                    this.MGAUSS = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MCTADJ")
                {
                    this.MCTADJ = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MCTSG")
                {
                    this.MCTSG = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MSLUG")
                {
                    this.MSLUG = Convert.ToInt32(m_dic.Value);
                }

                if (m_dic.Key == "MTRANS")
                {
                    this.MTRANS = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MTIP")
                {
                    this.MTIP = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MRISE")
                {
                    this.MRISE = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MBDW")
                {
                    this.MBDW = Convert.ToInt32(m_dic.Value);
                }

                if (m_dic.Key == "MSHEAR")
                {
                    this.MSHEAR = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MSPLIT")
                {
                    this.MSPLIT = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MCHEM")
                {
                    this.MCHEM = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MAQCHEM")
                {
                    this.MAQCHEM = Convert.ToInt32(m_dic.Value);
                }

                if (m_dic.Key == "MWET")
                {
                    this.MWET = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MDRY")
                {
                    this.MDRY = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MTILT")
                {
                    this.MTILT = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MDISP")
                {
                    this.MDISP = Convert.ToInt32(m_dic.Value);
                }

                if (m_dic.Key == "MTURBV")
                {
                    this.MTURBVW = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MDISP2")
                {
                    this.MDISP2 = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MTAULY")
                {
                    this.MTAULY = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MTAUADV")
                {
                    this.MTAUADV = Convert.ToInt32(m_dic.Value);
                }

                if (m_dic.Key == "MCTURB")
                {
                    this.MCTURB = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MROUGH")
                {
                    this.MROUGH = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MPARTL")
                {
                    this.MPARTL = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MPARTLBA")
                {
                    this.MPARTLBA = Convert.ToInt32(m_dic.Value);
                }

                if (m_dic.Key == "MTINV")
                {
                    this.MTINV = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MPDF")
                {
                    this.MPDF = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MSGTIBL")
                {
                    this.MSGTIBL = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MBCON")
                {
                    this.MBCON = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MSOURCE")
                {
                    this.MSOURCE = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MFOG")
                {
                    this.MFOG = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MREG")
                {
                    this.MREG = Convert.ToInt32(m_dic.Value);
                }
            }
        }

        public override string WriteToGroup()
        {
            string ResultStr = "", TempStr = "";

            TempStr = StrWriter.GetCLine();
            TempStr += "INPUT GROUP: 2 -- Technical options" + "\r\n";
            ResultStr += TempStr;

            TempStr = StrWriter.GetCLine();
            ResultStr += TempStr;

            TempStr = "! MGAUSS = " + MGAUSS.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MCTADJ = " + MCTADJ.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MCTSG = " + MCTSG.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MSLUG = " + MSLUG.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MTRANS = " + MTRANS.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MTIP = " + MTIP.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MRISE = " + MRISE.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MBDW = " + MBDW.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MSHEAR = " + MSHEAR.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MSPLIT = " + MSPLIT.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MCHEM = " + MCHEM.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MAQCHEM = " + MAQCHEM.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MWET = " + MWET.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MDRY = " + MDRY.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MTILT = " + MTILT.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MDISP = " + MDISP.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MTURBVW = " + MTURBVW.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MDISP2 = " + MDISP2.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MTAULY = " + MTAULY.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MTAUADV = " + MTAUADV.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MCTURB = " + MCTURB.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MROUGH = " + MROUGH.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MPARTL = " + MPARTL.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MPARTLBA = " + MPARTLBA.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MTINV = " + MTINV.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MPDF = " + MPDF.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MSGTIBL = " + MSGTIBL.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MBCON = " + MBCON.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MSOURCE = " + MSOURCE.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MFOG = " + MFOG.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MREG = " + MREG.ToString() + " !" + "\r\n";
            ResultStr += TempStr;


            ResultStr += "!END!" + "\r\n";

            return ResultStr;
        }
    }
}
